home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Src Code / MYPOINT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  2.9 KB  |  102 lines

  1. {**********************************************}
  2. {   TMyPointSeries                             }
  3. {   Copyright (c) 1997-98 by David Berneda     }
  4. {      Series Developer Kit Example            }
  5. {**********************************************}
  6. {$I teedefs.inc}
  7. unit MyPoint;
  8.  
  9. interface
  10.  
  11. Uses SysUtils,Classes,Graphics,Teengine,Chart,Series,TeCanvas;
  12.  
  13. { This sample Series derives from TPointSeries.
  14.   It shows how to override the DrawValue method, which is called
  15.   every time every point in the Series should be displayed.
  16.  
  17.   In this sample, one horizontal line and one vertical line are
  18.   drawn from the axis to every point.
  19.   A new TPen property is published to control the lines attributes.
  20. }
  21.  
  22. Type TMyPointSeries=class(TPointSeries)
  23.      private
  24.        FLinesPen:TChartPen;
  25.        procedure SetLinesPen(Value:TChartPen);
  26.      protected
  27.        procedure DrawValue(ValueIndex:Longint); override;
  28.      public
  29.        Constructor Create(AOwner:TComponent); override;
  30.        Destructor Destroy; override;
  31.      published
  32.        property LinesPen:TChartPen read FLinesPen write SetLinesPen;
  33.      end;
  34.  
  35. implementation
  36.  
  37. Uses WinTypes,WinProcs,TeeProco;  { <-- only for the "Samples" constant }
  38.  
  39. { overrided constructor to change default pointer style and 3D }
  40. Constructor TMyPointSeries.Create(AOwner:TComponent);
  41. begin
  42.   inherited Create(AOwner);
  43.   Pointer.Draw3D:=False;
  44.   Pointer.Style:=psDiamond;
  45.   FLinesPen:=CreateChartPen;  { <-- create new pen property }
  46.   FLinesPen.Color:=clRed;     { <-- set default color to Red }
  47. end;
  48.  
  49. { overrided DrawValue to draw additional lines for each point }
  50. procedure TMyPointSeries.DrawValue(ValueIndex:Longint);
  51. var tmpX,tmpY:Longint;
  52. begin
  53.   With ParentChart,Canvas do
  54.   begin
  55.     { calculate X and Y screen positions in pixels }
  56.     tmpX:=CalcXPos(ValueIndex);
  57.     tmpY:=CalcYPos(ValueIndex);
  58.  
  59.     { change brush and pen attributes }
  60.     Brush.Style:=bsClear;
  61.     Canvas.BackMode:=cbmTransparent;
  62.     { use "MyPoint" pen... }
  63.     Pen.Assign(FLinesPen);
  64.  
  65.     { draw the horizontal and vertical lines }
  66.     MoveTo3D(ChartRect.Left,tmpY,MiddleZ);
  67.     LineTo3D(tmpX,tmpY,MiddleZ);
  68.     LineTo3D(tmpX,ChartRect.Bottom,MiddleZ);
  69.   end;
  70.  
  71.   { draw the point }
  72.   inherited DrawValue(ValueIndex);
  73. end;
  74.  
  75. procedure TMyPointSeries.SetLinesPen(Value:TChartPen);
  76. begin
  77.   FLinesPen.Assign(Value);   { <-- set new property values }
  78. end;
  79.  
  80. Destructor TMyPointSeries.Destroy;
  81. begin
  82.   FLinesPen.Free;   { <-- remember to destroy private properties }
  83.   inherited Destroy;
  84. end;
  85.  
  86. { Series/Functions Registration/Un-Registration }
  87.  
  88. Procedure MyPointExitProc; far;
  89. begin
  90.   UnRegisterTeeSeries([TMyPointSeries]);
  91. end;
  92.  
  93. initialization
  94.   RegisterTeeSeries( TMyPointSeries, 'MyPoint', TeeMsg_GallerySamples, 1 );
  95. {$IFDEF D1}
  96.   AddExitProc(MyPointExitProc);
  97. {$ELSE}
  98. finalization
  99.   MyPointExitProc;
  100. {$ENDIF}
  101. end.
  102.